import { ADMIN, ADMIN_ARTICLE, ADMIN_CATEGORY, ADMIN_MEMBER, ADMIN_PROTOCOL } from '../actionTypes';

const initialState = {
  member: {
    modalShow: false,
    data: [],
    modalId: '',
    modalName: '',
    modalContent: '',
  },
  carousel: [],
  protocol: '',
  article: {
    list: [],  // 所有文章列表
    category: [],  // 所有栏目
    id: '',
    cid: '',
    title: '',
    top: 0,
    content: '',
    hot: [],
  },
  category: {
    list: [],
  },
};

const admin = (state = initialState, action) => {
  if (action.type === ADMIN) {
    return { ...state, ...action.payload };
  } else if (action.type === ADMIN_MEMBER) {
    return {
      ...state,
      ...{
        member: {
          ...state.member,
          ...action.payload,
        }
      }
    };
  } else if (action.type === ADMIN_ARTICLE) {
    return {
      ...state,
      ...{
        article: {
          ...state.article,
          ...action.payload,
        }
      }
    };
  } else if (action.type === ADMIN_CATEGORY) {
    return {
      ...state,
      ...{
        category: {
          ...state.category,
          ...action.payload,
        }
      }
    };
  } else if (action.type === ADMIN_PROTOCOL) {
    return {
      ...state,
      protocol: action.payload,
    };
  }
  return state;
};

export default admin;
